package net.ck.hzq;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;

import net.ck.hzq.wxapi.ResultActivity;

import org.devio.takephoto.model.TImage;
import org.devio.takephoto.model.TResult;

import java.io.File;
import java.util.ArrayList;

import base.BaseTakePhotoActivity;
import base.CustomHelper;

public class SampleAct extends BaseTakePhotoActivity {
    private CustomHelper customHelper;

    private LinearLayout linearLayout;
    @Override
    public int getLayoutId() {
        return R.layout.common_layout;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        View contentView = LayoutInflater.from(this).inflate(R.layout.common_layout, null);
//        setContentView(contentView);
//        imageView = findViewById(R.id.image_resu);
        linearLayout = findViewById(R.id.image_resu);

        customHelper = CustomHelper.of(contentView);
    }

    public void onClick(View view) {
        customHelper.onClick(view, getTakePhoto());
    }

    @Override
    public void takeCancel() {
        super.takeCancel();
    }

    @Override
    public void takeFail(TResult result, String msg) {
        super.takeFail(result, msg);
    }

    @Override
    public void takeSuccess(TResult result) {
        super.takeSuccess(result);
        showImg(result.getImages());
    }

    private void showImg(ArrayList<TImage> images) {
        Intent intent = new Intent(this, ResultActivity.class);
        intent.putExtra("images", images);
        startActivity(intent);

//        Glide.with(this).load(new File(images.get(images.size() - 1).getCompressPath())).into(imageView);


//        for (int i = 0, j = images.size(); i < j - 1; i += 2) {
//            View view = LayoutInflater.from(this).inflate(R.layout.image_show, null);
//            ImageView imageView1 = (ImageView) view.findViewById(R.id.imgShow1);
//            ImageView imageView2 = (ImageView) view.findViewById(R.id.imgShow2);
//            Glide.with(this).load(new File(images.get(i).getCompressPath())).into(imageView1);
//            Glide.with(this).load(new File(images.get(i + 1).getCompressPath())).into(imageView2);
//            linearLayout.addView(view);
//        }
//        if (images.size() % 2 == 1) {
//            View view = LayoutInflater.from(this).inflate(R.layout.image_show, null);
//            ImageView imageView1 = (ImageView) view.findViewById(R.id.imgShow1);
//            Glide.with(this).load(new File(images.get(images.size() - 1).getCompressPath())).into(imageView1);
//            linearLayout.addView(view);
//        }

    }

}
